from google.appengine.ext import webapp
from google.appengine.ext.webapp.util import run_wsgi_app
from google.appengine.api import mail


# Sends an email with the fields of the form
class FeedbackFormHandler(webapp.RequestHandler):


    def get(self):
        self.post()

    def post(self):
        
        name=self.request.get('realname')
        email=self.request.get('email')
        message_body = "Name: " + name + "\nEmail: " + email +"\n\n" + self.request.get('message')   
        message = mail.EmailMessage(sender="Feedback <feedback@dublin-nights.appspotmail.com>",
                                  to = "Dublin Nights <events.dublin.nights@gmail.com>",
                                  subject = "Feedback Form",
                                  body = message_body)
        message.send()
      
        self.response.out.write("""<META HTTP-EQUIV=Refresh CONTENT="3; URL=/">Thanks for your feedback! </br></br>You will be redirected to the Dublin Nights homepoge.""");  
    
application = webapp.WSGIApplication([('/send_feedback', FeedbackFormHandler)], debug=True)

def main():
    run_wsgi_app(application)

if __name__ == "__main__":
    main()